package top.lbqaq.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author luoboQAQ
 */
@WebServlet(name = "SecondServlet", value = "/2")
public class SecondServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        int num = Integer.parseInt(request.getParameter("num")!= null ? request.getParameter("num") : "0");
        response.getWriter().print(num);
        response.getWriter().print("<br/><table>");
        for (int i = 1; i <= num; i++) {
            response.getWriter().print("<tr>");
            for (int j = 1; j <= i; j++) {
                response.getWriter().print("<td>");
                response.getWriter().print(i+"*"+j+"="+i*j);
                response.getWriter().print("</td>");
            }
            response.getWriter().print("</tr>");
        }
        response.getWriter().print("</table>");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
